package ch07;

/**
 * A cash register totals up sales and computes due.
 * 
 * @author peter
 *
 */

public class CashRegister {
	
	private double purchase;
	private double payment;
	
	public CashRegister()
	{
		purchase = 0;
		payment = 0;
	}
	
	public void recordPurchase(double amount)
	{
		purchase += amount;
	}
	
	public void enterPayment(int dollars, int quarters, int dimes, int nickels, int pennies)
	{
		payment = dollars + quarters * Coin.QUARTER_VALUE + dimes * Coin.DIME_VALUE + nickels * Coin.NICLE_VALUE + pennies * Coin.PENNY_VALUE; 
	}
	
	public void enterpayment(int coinCount, Coin coin)
	{
		payment = coin.getValue() * coinCount;
	}
	
	public double giveChange()
	{
		double change = payment - purchase;
		purchase = 0;
		payment = 0;
		return change;
	}
	
	public int giveChange(Coin coinType)
	{
		double change = payment - purchase;
		int coinNum = (int) (change / coinType.getValue());
		return coinNum;
	}
}
